<?php
$id = 0;
$mod = $_GET['mod'];
$title_add = "Account";
if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $db = new MySQL();
    $sql = $db->select("select * from account where id='$id'");
    if ($db->numrows($sql) > 0)
        $row = $db->fetch($sql);
    $title_add = "Account";
}
?>

<script type="text/javascript">
    function checkinput()
    {
        if (document.frmedit.txtemail.value == "")
        {
            alert('Please enter email address for account!');
            document.frmedit.txtemail.focus();
            return false;
        }
        else if (!isEmail(document.frmedit.txtemail.value))
        {
            alert("Email address isn't corect. Please enter email for account again!");
            document.frmedit.txtemail.focus();
            return false;
        }

        return true;
    }
</script>
<div class="page-header">
    <div class="pull-left"><?= $title_add ?></div>
    <div class="pull-right"></div>
    <div class="clear"></div>
</div>

<form parsley-validate class="form-horizontal" role="form" name="frmedit" method="post" enctype="multipart/form-data" action="<?= $id==0?"?mod=$mod&act=process":"?mod=$mod&act=process&id=$id" ?>">
    <div class="form-group">
        <label class="col-sm-3 control-label">Username :</label>
        <div class="col-sm-9">
            <input parsley-required="true" name="txtuser" type="text" class="form-control" value="<?= $row['username'] ?>"  <?php if (isset($args['id'])) echo ' disabled=disabled'; ?> >
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">Password :</label>
        <div class="col-sm-9">
            <input parsley-required="true" name="txtpass" type="password" class="form-control" <?php if (isset($_GET['id'])) echo 'value="*******" disabled=disabled'; ?>>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">Email :</label>
        <div class="col-sm-9">
            <input parsley-required="true" parsley-type="email" name="txtemail" type="text" class="form-control" value="<?= $row['email'] ?>">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label">Permission :</label>
        <div class="col-sm-9">
            <div class="radio">
                <label>
                    <input name="rdper" type="radio" value="1" <? if($row['per']==1) echo "checked";?>>
                           Admin
                </label>
            </div>
            <div class="radio">
                <label>
                    <input name="rdper" type="radio" value="0" <? if($row['per']==0) echo "checked";?>>
                           User
                </label>
            </div>
        </div>

    </div>

    <div class="form-group">
        <div class="col-sm-offset-3 col-sm-9">
            <button type="submit" class="btn btn-primary">Save</button>
            <button type="reset" class="btn btn-default">Reset</button>
        </div>
    </div>
    <input type="hidden" name="form_" value="edit">
</form>
